package com.ymatou.iapi.godmch.testcase;

import groovyjarjarasm.asm.tree.IntInsnNode;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.applySupplierBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.getSupplierDepotListBean;
import com.ymatou.iapi.godmch.service.applySupplierCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getSupplierDepotListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.supplierInfo;
import com.ymttest.database.model.godmch.supplierInfoExample;
import com.ymttest.database.sqlwapper.godmch.supplierInfoWapper;
/**
*批量查询供货商仓库名称
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getSupplierDepotList{
	private static getSupplierDepotListBean bean;
	private static getSupplierDepotListCall call;
	private  supplierInfoExample supplierInfoExample=new supplierInfoExample();
	private  supplierInfoWapper supplierInfoWapper=new supplierInfoWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量查询供货商仓库名称");
	}

	@Before
	public void caseUp() {
		bean=new getSupplierDepotListBean();
		call=new getSupplierDepotListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws JSONException, InterruptedException {
		//验证
		supplierInfoExample.createCriteria().andSupplierIdIn(bean.getSupplierIdList());
		List<supplierInfo> supplierInfos=supplierInfoWapper.selectByExample(supplierInfoExample);
		JSONArray act_list=call.getSupplierDepotList();
		
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
		Logger.verifyEquals(supplierInfos.size(), act_list.length(), "验证返回的供货商与数据库的供货商一致");
		for(int i=0;i<supplierInfos.size();i++)
		{
			Logger.comment("### supplierId:"+act_list.getJSONObject(i).getInt("supplierId"));
		  Logger.verifyEquals(supplierInfos.get(i).getSupplierId(), act_list.getJSONObject(i).getInt("supplierId"), "验证返回的供货商supplierId值与数据库的供货商supplierId值一致");
		  Logger.verifyEquals(supplierInfos.get(i).getDepot(), act_list.getJSONObject(i).getString("depot"), "验证返回的供货商depot值与数据库的供货商depot值一致");
		}

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_001() {
		Logger.start(true,"正例-批量查询供货商仓库名称-同一独立商户-传入一个供货商-成功");
		try {
			//独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //审核通过
            GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            //修改
            GodmchManageCallService.editSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            List<Integer> supplierIdList=new ArrayList<Integer>();
            supplierIdList.add(applySupplierCall.getSupplierId());
            bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_002() {
		Logger.start(true,"正例-批量查询供货商仓库名称-同一独立商户-传入两个供货商-成功");
		try {
			//独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商1
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //审核通过1
            GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            //修改1
            GodmchManageCallService.editSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            //申请供货商2
            applySupplierBean applySupplierBean2=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall2=GodmchManageCallService.applySupplierCall(applySupplierBean2);
            //审核通过2
            GodmchManageCallService.approveSupplier(applySupplierBean2.getMchId(), applySupplierCall2.getSupplierId());
            //修改2
            GodmchManageCallService.editSupplier(applySupplierBean2.getMchId(), applySupplierCall2.getSupplierId());
            
            List<Integer> supplierIdList=new ArrayList<Integer>();
            supplierIdList.add(applySupplierCall.getSupplierId());
            supplierIdList.add(applySupplierCall2.getSupplierId());
            bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_003() {
		Logger.start(true,"正例-批量查询供货商仓库名称-不同独立商户-各商户传入一个供货商-成功");
		try {
			//独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			//独立商户2
			createIndepMchBean createIndepMchBean2=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall2=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean2);
            //申请供货商1
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //审核通过1
            GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            //修改1
            GodmchManageCallService.editSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            //申请供货商2
            applySupplierBean applySupplierBean2=GodmchManageCallService.initApplySupplier(createIndepMchCall2.getmchId());
            applySupplierCall applySupplierCall2=GodmchManageCallService.applySupplierCall(applySupplierBean2);
            //审核通过2
            GodmchManageCallService.approveSupplier(applySupplierBean2.getMchId(), applySupplierCall2.getSupplierId());
            //修改2
            GodmchManageCallService.editSupplier(applySupplierBean2.getMchId(), applySupplierCall2.getSupplierId());
            
            List<Integer> supplierIdList=new ArrayList<Integer>();
            supplierIdList.add(applySupplierCall.getSupplierId());
            supplierIdList.add(applySupplierCall2.getSupplierId());
            bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			check_verify();				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_004() {
		Logger.start(true,"正例-批量查询供货商仓库名称-不同独立商户-各商户传入两个供货商-成功");
		try {
			//独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			//独立商户2
			createIndepMchBean createIndepMchBean2=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall2=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean2);
            
            //申请供货商1
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //审核通过1
            GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            //修改1
            GodmchManageCallService.editSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            //申请供货商3
            applySupplierBean applySupplierBean3=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall3=GodmchManageCallService.applySupplierCall(applySupplierBean3);
            //审核通过3
            GodmchManageCallService.approveSupplier(applySupplierBean3.getMchId(), applySupplierCall3.getSupplierId());
            //修改3
            GodmchManageCallService.editSupplier(applySupplierBean3.getMchId(), applySupplierCall3.getSupplierId());
            
            
            //申请供货商2
            applySupplierBean applySupplierBean2=GodmchManageCallService.initApplySupplier(createIndepMchCall2.getmchId());
            applySupplierCall applySupplierCall2=GodmchManageCallService.applySupplierCall(applySupplierBean2);
            //审核通过2
            GodmchManageCallService.approveSupplier(applySupplierBean2.getMchId(), applySupplierCall2.getSupplierId());
            //修改2
            GodmchManageCallService.editSupplier(applySupplierBean2.getMchId(), applySupplierCall2.getSupplierId());
            
            //申请供货商4
            applySupplierBean applySupplierBean4=GodmchManageCallService.initApplySupplier(createIndepMchCall2.getmchId());
            applySupplierCall applySupplierCall4=GodmchManageCallService.applySupplierCall(applySupplierBean4);
            //审核通过4
            GodmchManageCallService.approveSupplier(applySupplierBean4.getMchId(), applySupplierCall4.getSupplierId());
            //修改4
            GodmchManageCallService.editSupplier(applySupplierBean4.getMchId(), applySupplierCall4.getSupplierId());
            
            
            List<Integer> supplierIdList=new ArrayList<Integer>();
            supplierIdList.add(applySupplierCall.getSupplierId());
            supplierIdList.add(applySupplierCall2.getSupplierId());
            supplierIdList.add(applySupplierCall3.getSupplierId());
            supplierIdList.add(applySupplierCall4.getSupplierId());
            bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			check_verify();				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_005() {
		Logger.start(true,"正例-批量查询供货商仓库名称-供货商id列表含不存在的供货商-返回一条供货商");
		try {
			//独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //审核通过
            GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            //修改
            GodmchManageCallService.editSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            List<Integer> supplierIdList=new ArrayList<Integer>();
            supplierIdList.add(applySupplierCall.getSupplierId());
            supplierIdList.add(11111111);
            bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_005_1() {
		Logger.start(true,"正例-批量查询供货商仓库名称-传入未修改的供货商-返回空");
		try {
			//独立商户
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //代理
            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //审核通过
            GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            List<Integer> supplierIdList=new ArrayList<Integer>();
            supplierIdList.add(applySupplierCall.getSupplierId());
            bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
			Logger.verifyEquals(0, call.getSupplierDepotList().length(), "验证返回的供货商为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_006() {
		Logger.start(true,"正例-批量查询供货商仓库名称-供货商id列表为空-成功");
		try {
//			//独立商户
//			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
//            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
//            //代理
//            GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
//            //申请供货商
//            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
//            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
//            //审核通过
//            GodmchManageCallService.approveSupplier(applySupplierBean.getMchId(), applySupplierCall.getSupplierId());
            
            List<Integer> supplierIdList=new ArrayList<Integer>();
//            supplierIdList.add(applySupplierCall.getSupplierId());
            bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getSupplierDepotList_007() {
		Logger.start(true,"正例-批量查询供货商仓库名称-SupplierIdList为空-成功");
		try {

         //   bean.setSupplierIdList(supplierIdList);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}